ArcGIS Runtime SDK for WPF - Library Reference
ProjectAsync(IEnumerable<Graphic>,SpatialReference) Method
See Also  Example
ESRI.ArcGIS.Client.Tasks Namespace > GeometryService Class > ProjectAsync Method : ProjectAsync(IEnumerable<Graphic>,SpatialReference) Method

graphics
The graphics containing the geometry to project.
outSpatialReference
The SpatialReference to project to.
Projects a set of Graphics into a new SpatialReference. Raises the ProjectCompleted event on success, or the TaskBase.Failed event on failure.

Syntax

Visual Basic (Declaration) 
Public Overloads Sub ProjectAsync( _
   ByVal graphics As IEnumerable(Of Graphic), _
   ByVal outSpatialReference As SpatialReference _
) 
C# 
public void ProjectAsync( 
   IEnumerable<Graphic> graphics,
   SpatialReference outSpatialReference
)

Remarks

The SpatialReference is a combination of an ellipsoid, datum, and a coordinate system used to display geographic data of the three dimensional Earth on a two dimensional surface (such as a piece of paper of computer monitor). A good article for describing how a spatial reference works can be found here.

The ProjectAsync Method can be used to project Graphics in the Projected Coordinate Systems and Geographic Coordinate Systems. The Well-known ID (aka. WKID) values are listed in these hyperlinked Coordinate System documents and serve as integer values when creating a new SpatialReference object using the constructor.

Excellent background information about map projects can be found in the ArcGIS Desktop Resource Center under the nodes of Professional Library | Guide books | Map projections. A good starting page is the "What are map projects?" web document.

Parameters

graphics
The graphics containing the geometry to project.
outSpatialReference
The SpatialReference to project to.

Example

How to use:

The Map Control on the left uses the Spatial Reference of WKID 102100. The Map Control on the right uses the Spatial Reference of WKID 4326. When the application loads the left Map Control will have a point added to the GraphicsLayer. Click the button to call the GeometryService.ProjectAsync Method to generate a new Graphic in the Spatial Reference of WKID 4326 and display it in the right Map Control.

The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.

The following screen shot corresponds to the code example in this page.

Using the Tasks.GeometryService.ProjectAsync Method.

XAMLCopy Code
<Grid x:Name="LayoutRoot">
    
  <!-- Add a Button to perform the GeometryService.ProjectAsync Method call. -->
  <Button Content="Project the MapPoint from WKID:102100 to WKID:4326" Height="23" 
          HorizontalAlignment="Left" Margin="12,147,0,0" Name="Button_ProjectAsync" 
          VerticalAlignment="Top" Width="748" Click="Button_ProjectAsync_Click"/>
  
  <!-- Add informational controls for the WKID 102100 Spatial Reference. -->
  <sdk:Label Height="20" HorizontalAlignment="Left" Margin="12,180,0,0" Name="Label_WKID_102100_X" 
             VerticalAlignment="Top" Width="15" Content="X:"/>
  <TextBox Height="20" HorizontalAlignment="Left" Margin="33,176,0,0" Name="TextBox_WKID_102100_X" 
           VerticalAlignment="Top" Width="329" />
  <sdk:Label Height="20" HorizontalAlignment="Left" Margin="12,202,0,0" Name="Label_WKID_102100_Y" 
             VerticalAlignment="Top" Width="15" Content="Y:"/>
  <TextBox Height="20" HorizontalAlignment="Left" Margin="33,198,0,0" Name="TextBox_WKID_102100_Y" 
           VerticalAlignment="Top" Width="329" />
  <sdk:Label Height="20" HorizontalAlignment="Left" Margin="12,223,0,0" Name="Label_WKID_102100" 
             VerticalAlignment="Top" Width="350" Content="WKID: 102100"/>
    
  <!-- 
  Add a Map Control zoomed into the State of Florida. The ArcGISTiledMapServiceLayer that is added
  dictates that the Spatial Reference of the Map Control will be of WKID 102100. 
  -->
  <esri:Map Background="White" HorizontalAlignment="Left" Margin="12,242,0,0" Name="Map_WKID_102100" 
            VerticalAlignment="Top" WrapAround="True" Height="350" Width="350"
            Extent="-9823888,2693745,-8830681,3686951">
    <esri:Map.Layers>
      <esri:LayerCollection>
        <esri:ArcGISTiledMapServiceLayer 
              Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
      </esri:LayerCollection>
    </esri:Map.Layers>
  </esri:Map>
  
  <!-- Add informational controls for the WKID 4326 Spatial Reference. -->
  <sdk:Label Content="X:" Height="20" HorizontalAlignment="Left" Margin="410,180,0,0" Name="Label_WKID_4326_X" 
             VerticalAlignment="Top" Width="15" />
  <TextBox Height="20" HorizontalAlignment="Left" Margin="431,176,0,0" Name="TextBox_WKID_4326_X" 
           VerticalAlignment="Top" Width="329" />
  <sdk:Label Content="Y:" Height="20" HorizontalAlignment="Left" Margin="410,202,0,0" Name="Label_WKID_4326_Y" 
             VerticalAlignment="Top" Width="15" />
  <TextBox Height="20" HorizontalAlignment="Left" Margin="431,198,0,0" Name="TextBox_WKID_4326_Y" 
           VerticalAlignment="Top" Width="329" />
  
  <sdk:Label Content="WKID: 4326" Height="20" HorizontalAlignment="Left" Margin="410,223,0,0" Name="Label_WKID_4326" 
             VerticalAlignment="Top" Width="350" />
  
  <!-- 
  Add a Map Control zoomed into the State of Florida. The ArcGISTiledMapServiceLayer that is added
  dictates that the Spatial Reference of the Map Control will be of WKID 4326. 
  -->
  <esri:Map Background="White" HorizontalAlignment="Left" Margin="410,242,0,0" 
            Name="Map_WKID_4326" VerticalAlignment="Top" WrapAround="True" Height="350" Width="350"
            Extent="-88.26,23.25,-79.32,32.19">
    <esri:Map.Layers>
      <esri:LayerCollection>
        <esri:ArcGISTiledMapServiceLayer 
              Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
      </esri:LayerCollection>
    </esri:Map.Layers>
  </esri:Map>
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="104" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="788" 
             TextWrapping="Wrap" Text="The Map Control on the left uses the Spatial Reference of WKID 102100. The Map Control
             on the right uses the Spatial Reference of WKID 4326. When the application loads the left Map Control will have a 
             point added to the GraphicsLayer. Click the button to call the GeometryService.ProjectAsync Method to generate 
             a new Graphic in the Spatial Reference of WKID 4326 and display it in the right Map Control." />
     
</Grid>
C#Copy Code
// Create a global varible for the GeometryService.
private ESRI.ArcGIS.Client.Tasks.GeometryService _GeometryService;
            
public MainPage()
{
  InitializeComponent();
  
  // Create a new GraphicsLayer for display in the WKID 102100 Spatial Reference.
  ESRI.ArcGIS.Client.GraphicsLayer myGraphicsLayer_WKID_102100 = new ESRI.ArcGIS.Client.GraphicsLayer();
  myGraphicsLayer_WKID_102100.ID = "MyGraphicsLayer_WKID_102100";
  
  // Create a new MapPoint.
  ESRI.ArcGIS.Client.Geometry.MapPoint myMapPoint_WKID_102100 = new ESRI.ArcGIS.Client.Geometry.MapPoint();
  myMapPoint_WKID_102100.X = -9171209.11;
  myMapPoint_WKID_102100.Y = 3448581.82;
  myMapPoint_WKID_102100.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(102100);
  
  // Create a new SimpleMarkerSymbol and set its Color, Style, and Size Properties.
  ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol mySimpleMarkerSymbol_WKID_102100 = new ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol();
  mySimpleMarkerSymbol_WKID_102100.Color = new System.Windows.Media.SolidColorBrush(Colors.Red);
  mySimpleMarkerSymbol_WKID_102100.Style = ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol.SimpleMarkerStyle.Circle;
  mySimpleMarkerSymbol_WKID_102100.Size = 10;
  
  // Create a new Graphic, set its Geometry and Symbol and add it to the GraphicsLayer.
  ESRI.ArcGIS.Client.Graphic myGraphic_WKID_102100 = new ESRI.ArcGIS.Client.Graphic();
  myGraphic_WKID_102100.Geometry = myMapPoint_WKID_102100;
  myGraphic_WKID_102100.Symbol = mySimpleMarkerSymbol_WKID_102100;
  myGraphicsLayer_WKID_102100.Graphics.Add(myGraphic_WKID_102100);
  
  // Add the GraphicsLayer to the Map Control
  Map_WKID_102100.Layers.Add(myGraphicsLayer_WKID_102100);
  
  // Create a new instance of the GeometryService. Use a valid URL that has a GeometryService set up and running.
  _GeometryService = new ESRI.ArcGIS.Client.Tasks.GeometryService("http://servicesbeta.esri.com/ArcGIS/rest/services/Geometry/GeometryServer");
  _GeometryService.DisableClientCaching = true;
  
  // The GeometryService runs Asynchronously, so we need to wire-up the GeometryService.ProjectCompleted Event. 
  _GeometryService.ProjectCompleted += GeometryService_ProjectCompleted;
  
  // Display the MapPoint X and Y values for the WKID 102100 in informational TextBoxes. 
  TextBox_WKID_102100_X.Text = myMapPoint_WKID_102100.X.ToString();
  TextBox_WKID_102100_Y.Text = myMapPoint_WKID_102100.Y.ToString();
}
            
private void Button_ProjectAsync_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // Executes when the users clicks the button. Takes the Graphics in the WKID 102100 SpatialReference
  // and runs the GeometryService.ProjectAsync Method on them to generate a new set of Graphics
  // based on the WKID 4326 SpatialReference.
  
  // Get the GraphicsLayer in the WKID 102100 SpatialReference.
  ESRI.ArcGIS.Client.GraphicsLayer myGraphicsLayer_WKID_102100 = (ESRI.ArcGIS.Client.GraphicsLayer)Map_WKID_102100.Layers["MyGraphicsLayer_WKID_102100"];
  
  // Call the Asynchronous Geometry.ProjectAsync Method. It will generate Graphics in the WKIS 4326 SpatialReference.
  _GeometryService.ProjectAsync(myGraphicsLayer_WKID_102100, new ESRI.ArcGIS.Client.Geometry.SpatialReference(4326));
}
            
private void GeometryService_ProjectCompleted(object sender, ESRI.ArcGIS.Client.Tasks.GraphicsEventArgs e)
{
  // Executes when the GeometryService.ProjectAsync has completed. The e.Results parameters has the new Graphics
  // Projected in the WKID 4326 SpatialReference.
  
  // Loop through each Graphic that was returned.
  foreach (ESRI.ArcGIS.Client.Graphic myGraphic in e.Results)
  {
    // Create a new GraphicsLayer for display in the WKID 4326 Spatial Reference.
    ESRI.ArcGIS.Client.GraphicsLayer myGraphicsLayer_WKID_4326 = new ESRI.ArcGIS.Client.GraphicsLayer();
    myGraphicsLayer_WKID_4326.ID = "MyGraphicsLayer_WKID_4326";
    
    // Create a new MapPoint.
    ESRI.ArcGIS.Client.Geometry.MapPoint myMapPoint_WKID_4326 = (ESRI.ArcGIS.Client.Geometry.MapPoint)myGraphic.Geometry;
    
    // Create a new SimpleMarkerSymbol and set its Color, Style, and Size Properties.
    ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol mySimpleMarkerSymbol_WKID_4326 = new ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol();
    mySimpleMarkerSymbol_WKID_4326.Color = new System.Windows.Media.SolidColorBrush(Colors.Red);
    mySimpleMarkerSymbol_WKID_4326.Style = ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol.SimpleMarkerStyle.Circle;
    mySimpleMarkerSymbol_WKID_4326.Size = 10;
    
    // Create a new Graphic, set its Geometry and Symbol and add it to the GraphicsLayer.
    ESRI.ArcGIS.Client.Graphic myGraphic_WKID_4326 = new ESRI.ArcGIS.Client.Graphic();
    myGraphic_WKID_4326.Geometry = myMapPoint_WKID_4326;
    myGraphic_WKID_4326.Symbol = mySimpleMarkerSymbol_WKID_4326;
    myGraphicsLayer_WKID_4326.Graphics.Add(myGraphic_WKID_4326);
    
    // Add the GraphicsLayer to the Map Control
    Map_WKID_4326.Layers.Add(myGraphicsLayer_WKID_4326);
    
    // Display the MapPoint X and Y values for the WKID 4326 in informational TextBoxes. 
    TextBox_WKID_4326_X.Text = myMapPoint_WKID_4326.X.ToString();
    TextBox_WKID_4326_Y.Text = myMapPoint_WKID_4326.Y.ToString();
  }
}
VB.NETCopy Code
' Create a global varible for the GeometryService.
Private _GeometryService As ESRI.ArcGIS.Client.Tasks.GeometryService
            
Public Sub New()
  InitializeComponent()
  
  ' Create a new GraphicsLayer for display in the WKID 102100 Spatial Reference.
  Dim myGraphicsLayer_WKID_102100 As ESRI.ArcGIS.Client.GraphicsLayer = New ESRI.ArcGIS.Client.GraphicsLayer
  myGraphicsLayer_WKID_102100.ID = "MyGraphicsLayer_WKID_102100"
  
  ' Create a new MapPoint.
  Dim myMapPoint_WKID_102100 As ESRI.ArcGIS.Client.Geometry.MapPoint = New ESRI.ArcGIS.Client.Geometry.MapPoint
  myMapPoint_WKID_102100.X = -9171209.11
  myMapPoint_WKID_102100.Y = 3448581.82
  myMapPoint_WKID_102100.SpatialReference = New ESRI.ArcGIS.Client.Geometry.SpatialReference(102100)
  
  ' Create a new SimpleMarkerSymbol and set its Color, Style, and Size Properties.
  Dim mySimpleMarkerSymbol_WKID_102100 As New ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol
  mySimpleMarkerSymbol_WKID_102100.Color = New System.Windows.Media.SolidColorBrush(Colors.Red)
  mySimpleMarkerSymbol_WKID_102100.Style = ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol.SimpleMarkerStyle.Circle
  mySimpleMarkerSymbol_WKID_102100.Size = 10
  
  ' Create a new Graphic, set its Geometry and Symbol and add it to the GraphicsLayer.
  Dim myGraphic_WKID_102100 As ESRI.ArcGIS.Client.Graphic = New ESRI.ArcGIS.Client.Graphic
  myGraphic_WKID_102100.Geometry = myMapPoint_WKID_102100
  myGraphic_WKID_102100.Symbol = mySimpleMarkerSymbol_WKID_102100
  myGraphicsLayer_WKID_102100.Graphics.Add(myGraphic_WKID_102100)
  
  ' Add the GraphicsLayer to the Map Control
  Map_WKID_102100.Layers.Add(myGraphicsLayer_WKID_102100)
  
  ' Create a new instance of the GeometryService. Use a valid URL that has a GeometryService set up and running.
  _GeometryService = New ESRI.ArcGIS.Client.Tasks.GeometryService("http://servicesbeta.esri.com/ArcGIS/rest/services/Geometry/GeometryServer")
  _GeometryService.DisableClientCaching = True
  
  ' The GeometryService runs Asynchronously, so we need to wire-up the GeometryService.ProjectCompleted Event. 
  AddHandler _GeometryService.ProjectCompleted, AddressOf GeometryService_ProjectCompleted
  
  ' Display the MapPoint X and Y values for the WKID 102100 in informational TextBoxes. 
  TextBox_WKID_102100_X.Text = myMapPoint_WKID_102100.X.ToString
  TextBox_WKID_102100_Y.Text = myMapPoint_WKID_102100.Y.ToString
  
End Sub
            
Private Sub Button_ProjectAsync_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' Executes when the users clicks the button. Takes the Graphics in the WKID 102100 SpatialReference
  ' and runs the GeometryService.ProjectAsync Method on them to generate a new set of Graphics
  ' based on the WKID 4326 SpatialReference.
  
  ' Get the GraphicsLayer in the WKID 102100 SpatialReference.
  Dim myGraphicsLayer_WKID_102100 As ESRI.ArcGIS.Client.GraphicsLayer = Map_WKID_102100.Layers("MyGraphicsLayer_WKID_102100")
  
  ' Call the Asynchronous Geometry.ProjectAsync Method. It will generate Graphics in the WKIS 4326 SpatialReference.
  _GeometryService.ProjectAsync(myGraphicsLayer_WKID_102100, New ESRI.ArcGIS.Client.Geometry.SpatialReference(4326))
  
End Sub
            
Private Sub GeometryService_ProjectCompleted(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Client.Tasks.GraphicsEventArgs)
  
  ' Executes when the GeometryService.ProjectAsync has completed. The e.Results parameters has the new Graphics
  ' Projected in the WKID 4326 SpatialReference.
  
  ' Loop through each Graphic that was returned.
  For Each myGraphic As ESRI.ArcGIS.Client.Graphic In e.Results
  
    ' Create a new GraphicsLayer for display in the WKID 4326 Spatial Reference.
    Dim myGraphicsLayer_WKID_4326 As ESRI.ArcGIS.Client.GraphicsLayer = New ESRI.ArcGIS.Client.GraphicsLayer
    myGraphicsLayer_WKID_4326.ID = "MyGraphicsLayer_WKID_4326"
    
    ' Create a new MapPoint.
    Dim myMapPoint_WKID_4326 As ESRI.ArcGIS.Client.Geometry.MapPoint = myGraphic.Geometry
    
    ' Create a new SimpleMarkerSymbol and set its Color, Style, and Size Properties.
    Dim mySimpleMarkerSymbol_WKID_4326 As New ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol
    mySimpleMarkerSymbol_WKID_4326.Color = New System.Windows.Media.SolidColorBrush(Colors.Red)
    mySimpleMarkerSymbol_WKID_4326.Style = ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol.SimpleMarkerStyle.Circle
    mySimpleMarkerSymbol_WKID_4326.Size = 10
    
    ' Create a new Graphic, set its Geometry and Symbol and add it to the GraphicsLayer.
    Dim myGraphic_WKID_4326 As ESRI.ArcGIS.Client.Graphic = New ESRI.ArcGIS.Client.Graphic
    myGraphic_WKID_4326.Geometry = myMapPoint_WKID_4326
    myGraphic_WKID_4326.Symbol = mySimpleMarkerSymbol_WKID_4326
    myGraphicsLayer_WKID_4326.Graphics.Add(myGraphic_WKID_4326)
    
    ' Add the GraphicsLayer to the Map Control
    Map_WKID_4326.Layers.Add(myGraphicsLayer_WKID_4326)
    
    ' Display the MapPoint X and Y values for the WKID 4326 in informational TextBoxes. 
    TextBox_WKID_4326_X.Text = myMapPoint_WKID_4326.X.ToString
    TextBox_WKID_4326_Y.Text = myMapPoint_WKID_4326.Y.ToString
    
  Next myGraphic
  
End Sub

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8

See Also

© ESRI, Inc. All Rights Reserved.